import {
    UserProfilesAPI
} from '@/request/api'

export default {
    namespaced: true,
    state: {
        //购物车数量
        cartTotal: 0,
        //用户信息
        userInfo: {
            headImg: require('../../assets/img/service.848ec511.png'),
            nickName: '昵称',
            coin: '1000'
        }
    },
    mutations: {
        updateUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal;
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                //清除昵称
                nickName: '--',
                // 清除鸡腿
                coin: '--',
                // 清除图片
                headImg: require('../../assets/img/userImg.f8bbec5e.png')
            }
        }
    },
    actions: {
        async asyncChangeUserInfo({
           commit
        }, payload) {
            let res = await UserProfilesAPI();
            commit('updateUserInfo',res.data)
       }
    }
}